package org.thirdHero.wx.request;

import com.alibaba.fastjson.JSON;
import com.github.binarywang.wxpay.bean.request.WxPayBaseRequest;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Strings;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import me.chanjar.weixin.common.annotation.Required;
import org.apache.commons.lang3.StringUtils;
import org.thirdHero.wx.constant.WxProFitSharingConstant;
import org.thirdHero.wx.utils.WxSignUtils;

@XStreamAlias("xml")
public class WxProfitSharingAddReceiverRequest extends WxProfitSharingBaseRequest {
    @Override
    protected void checkConstraints() throws WxPayException {
        if(receiver==null){
            throw new WxPayException("分账接收方必须输入");
        }
        if( (wxSharingReceiverRequest.getType().equals(WxProFitSharingConstant.MERCHANT_ID)
                || wxSharingReceiverRequest.getType().equals(WxProFitSharingConstant.PERSONAL_WECHATID))
                && Strings.isNullOrEmpty(wxSharingReceiverRequest.getName())){
            throw new WxPayException("分账接收方类型是MERCHANT_ID时，是商户全称（必传）");
        }
        if(wxSharingReceiverRequest.getRelation_type().equals(WxProFitSharingConstant.CUSTOM)
            && Strings.isNullOrEmpty(wxSharingReceiverRequest.getCustomRelation())){
            throw new WxPayException("当字段relation_type的值为CUSTOM时，custom_relation必填");
        }
    }



    @XStreamOmitField
    private WxSharingReceiverRequest wxSharingReceiverRequest;

    @Required
    @XStreamAlias("receiver")
    private String receiver;

    public WxSharingReceiverRequest getWxSharingReceiverRequest() {
        return wxSharingReceiverRequest;
    }

    public void setWxSharingReceiverRequest(WxSharingReceiverRequest wxSharingReceiverRequest) {
        this.wxSharingReceiverRequest = wxSharingReceiverRequest;
        this.receiver = WxProFitSharingConstant.CDATA_PREFIX+JSON.toJSONString(wxSharingReceiverRequest)+WxProFitSharingConstant.CDATA_SUFFIX;
    }


}
